package com.sgb.kjwl.viewmodel.shopping;


import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.model.entity.ShoppingCarEntity;
import com.sgb.kjwl.repository.ShoppingCarRepertory;
import com.sgb.kjwl.view.ui.fragment.shop.ShopPicklFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.functions.Consumer;

public class ShopPickModel extends BaseViewModel {
    private ShopPicklFragment fragment;
    private ShoppingCarRepertory repertory;
    private int page = 1;
    private int size = 10;
    public int total;

    public ShopPickModel(ShopPicklFragment fragment, ShoppingCarRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
    }

    public void refresh() {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        repertory.getShoppingCarEntity(repertory.getAreaCode())
                .subscribe(new Consumer<BaseEntity<List<ShoppingCarEntity>>>() {
                    @Override
                    public void accept(BaseEntity<List<ShoppingCarEntity>> shoppingCarEntity) throws Exception {
                        DialogHelper.dismissProgressDialog();
                        fragment.refresh(null);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) {
                        DialogHelper.dismissProgressDialog();
                        List<String> stringList = new ArrayList<>();
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        fragment.refresh(stringList);
                        MLog.d(AppConstant.API_LOG, throwable.getMessage());
                    }
                });

        //测试数据
    }

    public void lodaMore() {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        repertory.getShoppingCarEntity(repertory.getAreaCode())
                .subscribe(new Consumer<BaseEntity<List<ShoppingCarEntity>>>() {
                    @Override
                    public void accept(BaseEntity<List<ShoppingCarEntity>> shoppingCarEntity) throws Exception {
                        DialogHelper.dismissProgressDialog();
                        fragment.loadMore(null);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) {
                        DialogHelper.dismissProgressDialog();
                        MLog.d(AppConstant.API_LOG, throwable.getMessage());
                        List<String> stringList = new ArrayList<>();
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        stringList.add("测试数据");
                        fragment.loadMore(stringList);
                    }
                });

        //测试数据
    }

}
